home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 011-020 / amok13 / flipmouse / flipmouse.mod < prev    next >
Text File  |  1993-11-04  |  5KB  |  167 lines

  1. (*---------------------------------------------------------------------------
  2.    :Program.    FlipMouse.mod
  3.    :Author.     Fridtjof Björn Siebert
  4.    :Address.    Nobileweg 67, D-7-Stgt-40
  5.    :Phone.      (0)711/822509
  6.    :Shortcut.   [fbs]
  7.    :Version.    1.0
  8.    :Date.       29-Dec-88 04:38:09
  9.    :Copyright.  PD
  10.    :Language.   MODULA-II
  11.    :Translator. M2Amiga v3.1d
  12.    :Contents.   Programm invert all mouse movements.
  13.    :Remark.     This is senseless!
  14. ---------------------------------------------------------------------------*)
  15.  
  16. MODULE FlipMouse;
  17.  
  18. FROM SYSTEM      IMPORT ADR, SETREG, REG, LONGSET, BITSET, ADDRESS, CAST;
  19. FROM Arts        IMPORT Assert,TermProcedure;
  20.  
  21. FROM Exec        IMPORT OpenDevice, CloseDevice, DoIO, IOFlagSet,
  22.                         MsgPortPtr, IOStdReqPtr, Interrupt, Signal,
  23.                         FindTask, TaskPtr, Wait, AllocSignal, FreeSignal;
  24. FROM ExecSupport IMPORT CreatePort, DeletePort, CreateStdIO, DeleteStdIO;
  25. FROM Input       IMPORT inputName, addHandler, remHandler, writeEvent;
  26. FROM InputEvent  IMPORT InputEvent, InputEventPtr, Class;
  27. FROM Intuition   IMPORT Preferences, PreferencesPtr, GetPrefs, SetPrefs;
  28. FROM Heap        IMPORT Allocate;
  29.  
  30. (*------  VARs:  ------*)
  31.  
  32. VAR
  33.   InputDevPort, TimerPort: MsgPortPtr;       (* My MessagePorts *)
  34.   InputRequestBlock: IOStdReqPtr;
  35.   HandlerStuff: Interrupt;
  36.   Ev, TraceEv: InputEventPtr;
  37.   InputOpen, HandlerActive: BOOLEAN;
  38.   OldPrefs, NewPrefs: PreferencesPtr;
  39.   MyTask: TaskPtr;
  40.   PrefsSet: BOOLEAN;
  41.   x,y: CARDINAL;
  42.   MySignal: INTEGER;
  43.  
  44. (*------  Input Handler:  ------*)
  45.  
  46. PROCEDURE FlipHandler(); (* $S- *)
  47.  
  48. BEGIN
  49.   Ev := ADDRESS(REG(8));      (* this gets InputEventList from A0 *)
  50.     (* A1 is ignored here 'cause there no memory needed *)
  51.   TraceEv := Ev;
  52.   WHILE TraceEv#NIL DO
  53.     WITH TraceEv^ DO
  54.       IF (class=rawmouse) THEN
  55.         x:=-x; y:=-y;
  56.       ELSIF (class=rawkey) AND (code=45H) THEN
  57.         Signal(MyTask,LONGSET{MySignal}); (* break myself. Isn't that nice? *)
  58.       END;
  59.     END;
  60.     TraceEv := TraceEv^.nextEvent;
  61.   END;
  62.   SETREG(0,Ev); (* Return eventlists address *)
  63. END FlipHandler; (* $S+ *)
  64.  
  65. (*------  CleanUp:  ------*)
  66.  
  67. PROCEDURE CleanUp();
  68.  
  69. BEGIN
  70.  
  71. (*------  Old Preferences:  ------*)
  72.  
  73.   IF PrefsSet THEN
  74.     SetPrefs(OldPrefs,SIZE(Preferences),TRUE);
  75.   END;
  76.  
  77. (*------  Remove Inputhandler:  ------*)
  78.  
  79.   IF HandlerActive THEN
  80.     WITH InputRequestBlock^ DO
  81.       command := remHandler;
  82.       data := ADR(HandlerStuff);
  83.     END;
  84.     DoIO(InputRequestBlock);
  85.   END;
  86.  
  87. (*------  Close Input-Device:  ------*)
  88.  
  89.   IF InputOpen THEN
  90.     CloseDevice(InputRequestBlock);
  91.     DeleteStdIO(InputRequestBlock);
  92.     DeletePort(InputDevPort);
  93.   END;
  94.  
  95. (*------  Free Signal:  ------*)
  96.  
  97.   IF MySignal>=0 THEN FreeSignal(MySignal) END;
  98.  
  99. END CleanUp;
  100.  
  101. (*------  MAIN:  ------*)
  102.  
  103. BEGIN
  104.  
  105. (*------  Init:  ------*)
  106.  
  107.   InputOpen := FALSE; HandlerActive := FALSE; PrefsSet := FALSE;
  108.   MySignal := -1; MyTask := FindTask(NIL);
  109.   TermProcedure(CleanUp);
  110.   MySignal := AllocSignal(-1);
  111.   Assert(MySignal>=0,ADR("No more signals!!"));
  112.  
  113. (*------  Open Input Device:  ------*)
  114.  
  115.   InputDevPort := CreatePort(ADR("InputPort.FlipMouse"),0);
  116.   Assert(InputDevPort#NIL,ADR("CreatePort failed"));
  117.   InputRequestBlock := CreateStdIO(InputDevPort);
  118.   Assert(InputRequestBlock#NIL,ADR("CreateStdIO failed"));
  119.   OpenDevice(ADR(inputName),0,InputRequestBlock,LONGSET{});
  120.   InputOpen := TRUE;
  121.  
  122. (*------  Add Input-Handler:  ------*)
  123.  
  124.   WITH HandlerStuff DO
  125.     data := NIL;
  126.     node.pri := 51;
  127.     code := ADR(FlipHandler);
  128.   END;
  129.   WITH InputRequestBlock^ DO
  130.     command := addHandler;
  131.     data := ADR(HandlerStuff);
  132.   END;
  133.   DoIO(InputRequestBlock);
  134.   HandlerActive := TRUE;
  135.  
  136. (*------  Modify Preferences:  ------*)
  137.  
  138.   Allocate(OldPrefs,SIZE(Preferences));
  139.   Allocate(NewPrefs,SIZE(Preferences));
  140.   Assert((OldPrefs#NIL) AND (NewPrefs#NIL),ADR("Out of Memory!!!"));
  141.   GetPrefs(OldPrefs,SIZE(Preferences));
  142.   NewPrefs^ := OldPrefs^;
  143.   WITH NewPrefs^ DO
  144.     FOR y:=0 TO 15 DO
  145.       pointerMatrix[y+y+2] := 0;
  146.       pointerMatrix[y+y+3] := 0;
  147.       FOR x:=0 TO 15 DO
  148.         IF x IN CAST(BITSET,OldPrefs^.pointerMatrix[32-y-y]) THEN
  149.           INCL(CAST(BITSET,pointerMatrix[y+y+2]),15-x);
  150.         END;
  151.         IF x IN CAST(BITSET,OldPrefs^.pointerMatrix[33-y-y]) THEN
  152.           INCL(CAST(BITSET,pointerMatrix[y+y+3]),15-x);
  153.         END;
  154.       END;
  155.     END;
  156.     xOffset := -15-xOffset;
  157.     yOffset := -15-yOffset;
  158.     PrefsSet := TRUE;
  159.     SetPrefs(NewPrefs,SIZE(Preferences),TRUE);
  160.   END;
  161.  
  162. (*------  Wait a while:  ------*)
  163.  
  164.   IF Wait(LONGSET{MySignal})=LONGSET{} THEN END;
  165.  
  166. END FlipMouse.
  167.